package org.mch.swingm.core;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;

import javax.swing.JDialog;

import org.mch.comm.itf.IMLogger;
import org.mch.comm.loging.MComLogger;

/**
 * 描述：；<BR/>
 * 
 * @author MCH；Date：2008-06-18；<BR/>
 *
 */
public class MDialog extends JDialog {
	private static final long serialVersionUID = 4250875680845337211L;
	private IMLogger log;

	public MDialog() {
		super();
		log = createLog();
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	protected IMLogger createLog() {
		return new MComLogger(getClass());
	}

	public MDialog(Frame owner) {
		super(owner, false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	/**
	 * 居中显示
	 */
	public void showCenter() {
		Toolkit kit = Toolkit.getDefaultToolkit(); // 定义工具包
		Dimension screenSize = kit.getScreenSize(); // 获取屏幕的尺寸
		int screenWidth = screenSize.width / 2; // 获取屏幕的宽
		int screenHeight = screenSize.height / 2; // 获取屏幕的高
		int height = getHeight();
		int width = getWidth();
		// 移动TestFrame至居中位置
		setLocation(screenWidth - width / 2, screenHeight - height / 2 - 50);
		setVisible(true);
	}

	public IMLogger log() {
		return log;
	}

}
